﻿using CommunityToolkit.Mvvm.ComponentModel;
using LiveCharts;
using LiveCharts.Defaults;

namespace Company.Shell.Models
{
    /// <summary>
    /// 程序文件
    /// </summary>
    public class ProgramEntity : ObservableObject
    {
        public ProgramEntity()
        {
            Step = MaxXAxis / 12;
        }
        public string? Guid { get; set; }
        private string name = string.Empty;
        /// <summary>
        /// 程序名
        /// </summary>
        public string Name 
        { 
            get { return name; } 
            set { SetProperty(ref name, value); }
        }

        private ChartValues<ObservablePoint> temperatures = new();
        /// <summary>
        /// 温度曲线坐标集合
        /// </summary>
        public ChartValues<ObservablePoint> Temperatures
        {
            get { return temperatures; }
            set { SetProperty(ref temperatures, value); }
        }

        private ChartValues<ObservablePoint> humidities = new();
        /// <summary>
        /// 湿度曲线坐标集合
        /// </summary>
        public ChartValues<ObservablePoint> Humidities
        {
            get { return humidities; }
            set { SetProperty(ref humidities, value); }
        }

        private double maxXAxis = 1440;
        /// <summary>
        /// X轴最大值（分钟数）
        /// </summary>
        public double MaxXAxis
        {
            get { return maxXAxis; }
            set { SetProperty(ref maxXAxis, value); }
        }

        private double step = 120;
        /// <summary>
        /// X轴刻度值
        /// </summary>
        public double Step
        {
            get { return step; }
            set { SetProperty(ref step, value); }
        }
        /// <summary>
        /// 以天为单位增加X轴的量程
        /// </summary>
        /// <returns></returns>
        public  double IncreaseXAxis()
        {
            MaxXAxis += 1440;
            if (MaxXAxis > 1440 * 7)
            {
                MaxXAxis = 1440 * 7;
            }
            Step = MaxXAxis / 12;
            return MaxXAxis;
        }

        /// <summary>
        /// 以天为单位减少X轴的量程
        /// </summary>
        /// <returns></returns>
        public double DecreaseXAxis()
        {
            MaxXAxis -= 1440;
            if (MaxXAxis < 1440)
            {
                MaxXAxis = 1440 ;
            }
            Step = MaxXAxis / 12;
            return MaxXAxis;
        }
    }
}
